package com.iespring.controller.admin.promotion;

import com.iespring.bean.admin.promotion.bo.MallCouponBo;
import com.iespring.bean.admin.promotion.bo.MallCouponForCreateBo;
import com.iespring.bean.admin.promotion.po.MallCoupon;
import com.iespring.bean.admin.promotion.po.MallCouponUser;
import com.iespring.bean.common.BasePageInfo;
import com.iespring.bean.common.BaseRespVo;
import com.iespring.bean.common.CommonData;
import com.iespring.service.poromotion.PromotionCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author:ZhangShuPeng
 * @Date:2022/12/29/15:06
 * @Description:
 */
@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    PromotionCouponService promotionCouponService;

    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info, String name, Short type, Short status) {

        CommonData<MallCoupon> data = promotionCouponService.list(info, name, type, status);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);

        return baseRespVo;
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody MallCouponForCreateBo mallCouponForCreateBo) {

        BaseRespVo baseRespVo = promotionCouponService.create(mallCouponForCreateBo);

        return baseRespVo;
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MallCouponBo mallCouponBo) {

        BaseRespVo baseRespVo = promotionCouponService.update(mallCouponBo);

        return baseRespVo;
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MallCoupon mallCoupon) {

        int rows = promotionCouponService.delete(mallCoupon);
        BaseRespVo baseRespVo = BaseRespVo.ok(rows);

        return baseRespVo;
    }

    @RequestMapping("listuser")
    public BaseRespVo listuser(BasePageInfo info, int couponId) {

        CommonData<MallCouponUser> data = promotionCouponService.listuser(info, couponId);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);

        return baseRespVo;
    }

    @RequestMapping("read")
    public BaseRespVo read(int id) {

        MallCoupon data = promotionCouponService.read(id);
        BaseRespVo baseRespVo = BaseRespVo.ok(data);

        return baseRespVo;
    }
}
